﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using OL.FrameCore.Infrastructure.Code;

namespace OL.FrameCore.Infrastructure.UnitOfWork
{
    public static class UnitOfWorkServiceCollectionExtensions
    {
		public static IServiceCollection AddUnitOfWork<TContext>(this IServiceCollection services) where TContext : DbContext
		{
			//ServiceCollectionServiceExtensions.AddScoped<IRepositoryFactory, UnitOfWork<TContext>>(services);
			//ServiceCollectionServiceExtensions.AddScoped<IRepositoryBase<TEntity>, RepositoryBase<TEntity>>(services);
			ServiceCollectionServiceExtensions.AddScoped<IUnitOfWork, EFUnitOfWork<TContext>>(services);
			ServiceCollectionServiceExtensions.AddScoped<IUnitOfWork<TContext>, EFUnitOfWork<TContext>>(services);
			//ServiceCollectionServiceExtensions.AddScoped<typeof( IRepositoryBase<>), typeof(RepositoryBase<>)> (services);

			services.RegisterScope(typeof(IRepositoryBase<>));

			return services;
		}

		public static IServiceCollection AddReadUnitOfWork<TContext>(this IServiceCollection services) where TContext : DbContext
		{
			//ServiceCollectionServiceExtensions.AddScoped<IRepositoryFactory, UnitOfWork<TContext>>(services);
			//ServiceCollectionServiceExtensions.AddScoped<IRepositoryBase<TEntity>, RepositoryBase<TEntity>>(services);
			//ServiceCollectionServiceExtensions.AddScoped<IUnitOfWork, EFUnitOfWork<TContext>>(services);
			ServiceCollectionServiceExtensions.AddScoped<IUnitOfWork<TContext>, EFUnitOfWork<TContext>>(services);
			//ServiceCollectionServiceExtensions.AddScoped<typeof( IRepositoryBase<>), typeof(RepositoryBase<>)> (services);

			//services.RegisterScope(typeof(IRepositoryBase<>));

			return services;
		}

	}
}
